package learn.unpacking.client;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

public class ClientHandlerStickybag extends ChannelInboundHandlerAdapter {

    private String message = "hello world = =";

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        byte[] bytes = message.getBytes();
        ByteBuf byteBuf = null;
        for(int i=0;i<100;i++){
            //申请缓存空间
            byteBuf = Unpooled.buffer(bytes.length);
            //将数据写入到缓存
            byteBuf.writeBytes(bytes);
            //将缓存中的数据写入到Channel
            ctx.writeAndFlush(byteBuf);
        }

        //        ctx.channel().writeAndFlush(message);
        //        ctx.channel().writeAndFlush(message);

    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        ctx.close();
    }
}
